import Types from '../../types';
import {load, save} from '../../../common/Storage';
import {loginByUserPhone} from '../../../api/UserApi';

/**
 * token登录
 * @returns {function(*)}
 */
export function onLoginByPhone() {
  return async dispatch => {
    const token = await load('token');
    const res = await loginByUserPhone(token);
    if (res) {
      save('token', res.data.token);
    }
    dispatch({type: Types.LOGIN_BY_PHONE, user: res.data});
  };
}
